@extends('app')
@include('UEditor::head')
@section('content')
<link rel="stylesheet" href="{{ asset('/css/editor.css') }}" />
<style>
    #editor {overflow:scroll; max-height:300px}
</style>
{{-- 表单验证错误信息 --}}
@if ($errors->any())
        <div class="alert alert-danger">
            @foreach($errors->all() as $error)
                <p>{{ $error }}</p>
            @endforeach
        </div>
@endif
<ul class="nav nav-tabs">
    <li ><a href="{{ url('/admin/enterprise/auth_type')}}">认证类别</a></li>
    <li class="active"><a href="{{ url('/admin/enterprise/auth_type/create') }}">添加</a></li>
</ul>
<form id="newsForm" method="post" action="/admin/enterprise/auth_type">
    <div class="panel panel-default description2">
        <div class="form-group">
            <!--             <label for="title" class="col-sm-2 control-label">标题：</label> -->
            <!--             <div class="col-sm-10"> -->
            <input type="text" class="form-control" name="name" id="name" placeholder="认证类别" value="@if ($blademod == 'edit') {!! $auth->name !!} @endif">
            <!--             </div> -->
        </div>
        <h4>相册：</h4>
        <div class="form-group">
            <input id="uploadimg" name="uploadimg" type="file" multiple="true">
            <div id="imgbox" class="dustbin">
                @if ($blademod == 'edit')
                    <img src='{{ $auth->icon }}' />
                    <input type='hidden' name='icon' value='{{ $auth->icon }}' />
                @else
                    <input type="hidden" name="icon" value="" />
                @endif
            </div>
        </div>
        <h4 class="header green clearfix">
            简介
        </h4>
 <!--       <div class="wysiwyg-editor" id="editor1">我是测试内容哦！</div>
        <div class="hr hr-double dotted"></div>

        <script src="{{ asset('/assets/js/jquery.hotkeys.min.js') }}"></script>
        <script src="{{ asset('/assets/js/bootstrap-wysiwyg.min.js') }}"></script>
     <script src="{{ asset('/assets/js/ace-elements.min.js') }}"></script>
        <script type="text/javascript">
            function showErrorAlert (reason, detail) {
              var msg='';
              if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
              else {
                console.log("error uploading file", reason, detail);
              }
              $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+
               '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
            }
            jQuery(function($){
  //but we want to change a few buttons colors for the third style
        $('#editor1').css({'height':'600px'}).ace_wysiwyg({
          toolbar:
          [
            'font',
            null,
            'fontSize',
            null,
            {name:'bold', className:'btn-info'},
            {name:'italic', className:'btn-info'},
            {name:'strikethrough', className:'btn-info'},
            {name:'underline', className:'btn-info'},
            null,
            {name:'insertunorderedlist', className:'btn-success'},
            {name:'insertorderedlist', className:'btn-success'},
            {name:'outdent', className:'btn-purple'},
            {name:'indent', className:'btn-purple'},
            null,
            {name:'justifyleft', className:'btn-primary'},
            {name:'justifycenter', className:'btn-primary'},
            {name:'justifyright', className:'btn-primary'},
            {name:'justifyfull', className:'btn-inverse'},
            null,
            {name:'createLink', className:'btn-pink'},
            {name:'unlink', className:'btn-pink'},
            null,
            {name:'insertImage', className:'btn-success'},
            null,
            'foreColor',
            null,
            {name:'undo', className:'btn-grey'},
            {name:'redo', className:'btn-grey'}
          ],
          'wysiwyg': {
            fileUploadError: showErrorAlert
          }
        }).prev().addClass('wysiwyg-style2');



        $('#editor2').css({'height':'300px'}).ace_wysiwyg({
          toolbar_place: function(toolbar) {
            return $(this).closest('.widget-box').find('.widget-header').prepend(toolbar).children(0).addClass('inline');
          },
          toolbar:
          [
            'bold',
            {name:'italic' , title:'Change Title!', icon: 'icon-leaf'},
            'strikethrough',
            null,
            'insertunorderedlist',
            'insertorderedlist',
            null,
            'justifyleft',
            'justifycenter',
            'justifyright'
          ],
          speech_button:false
        });
  //Add Image Resize Functionality to Chrome and Safari
  //webkit browsers don't have image resize functionality when content is editable
  //so let's add something using jQuery UI resizable
  //another option would be opening a dialog for user to enter dimensions.
  if ( typeof jQuery.ui !== 'undefined' && /applewebkit/.test(navigator.userAgent.toLowerCase()) ) {

        var lastResizableImg = null;
        function destroyResizable() {
          if(lastResizableImg == null) return;
          lastResizableImg.resizable( "destroy" );
          lastResizableImg.removeData('resizable');
          lastResizableImg = null;
        }

    var enableImageResize = function() {
      $('.wysiwyg-editor')
      .on('mousedown', function(e) {
        var target = $(e.target);
        if( e.target instanceof HTMLImageElement ) {
          if( !target.data('resizable') ) {
            target.resizable({
              aspectRatio: e.target.width / e.target.height,
            });
            target.data('resizable', true);

            if( lastResizableImg != null ) {//disable previous resizable image
              lastResizableImg.resizable( "destroy" );
              lastResizableImg.removeData('resizable');
            }
            lastResizableImg = target;
          }
        }
      })
      .on('click', function(e) {
        if( lastResizableImg != null && !(e.target instanceof HTMLImageElement) ) {
          destroyResizable();
        }
      })
      .on('keydown', function() {
        destroyResizable();
      });
      }

    enableImageResize();
    /**
    //or we can load the jQuery UI dynamically only if needed
    if (typeof jQuery.ui !== 'undefined') enableImageResize();
    else {//load jQuery UI if not loaded
      $.getScript($path_assets+"/js/jquery-ui-1.10.3.custom.min.js", function(data, textStatus, jqxhr) {
        if('ontouchend' in document) {//also load touch-punch for touch devices
          $.getScript($path_assets+"/js/jquery.ui.touch-punch.min.js", function(data, textStatus, jqxhr) {
            enableImageResize();
          });
        } else  enableImageResize();
      });
    }
    */
  }


});
</script> -->

        <div class="form-group">
            <script id="description" name="description"  style="width:100%;margin:0 auto;height:100px;" type="text/plain">
            </script>
        </div> 

        <input type="hidden" name="auth_id" value="@if ($blademod == 'edit'){{ $auth->auth_id }} @else 0 @endif">
        {!! csrf_field() !!}
        <div class="form-inline mt20">
            <div class="form-group">
                <input type="submit" class="btn btn-info" id="organi_publish_save" value="submit" />
            </div>
            <div class="form-group col-xs-offset-1">
                <input type="reset" class="btn" value="reset" />
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">

   // 简介
    var ue = UE.getEditor('description');
    ue.ready(function() {
        ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.

        ue.setContent('@if ($blademod == "edit"){!! $auth->description !!}@endif'); //赋值
    });
    $(function(){

//         $('#editor1').focus(function(){
//             // alert('afdasfa');
//         });
        /***图片上传****/
        $("#uploadimg").uploadify({
            'formData'     : {
                'app':'auth',
                'fileField':'upfile',
                '_token':'{{ csrf_token() }}'
            },
            "width"           : 120,
            "height"          : 30,
            "queueSizeLimit"  :1,
            "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
            "fileObjName"     : "upfile",
            "buttonText"      : "上传图片",
            "uploader"        : '/admin/upload/uploadimg',
            'removeTimeout'   : 1,
            'fileTypeExts'    : '*.jpg; *.png; *.gif;',
            'onUploadSuccess':function(file, data, response){
                var data = eval('(' + data + ')');
                if (data.status == 'success') {

                    var html="<div style='width:90px; height:60px;float:left;'>"
                        +"<img src='"+data.attach+"' /><input type='hidden' name='icon' value='" + data.attach + "' />";
                        +"</div>"
                    $('#imgbox').html(html);
//                  bindImg();
                }else{
                    alert(data.msg);
                    return false;
                }
            }
        });

        });
</script>
@endsection
